[id].vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <template>
  2. <div id="newsList">
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <!-- 导航栏 -->
  6. <HomePageNavigation1></HomePageNavigation1>
  7. <!-- 列表页广告一 -->
  8. <HomeTopTen :imgurl="adImg1" v-if="adImg1"></HomeTopTen>
  9. <!-- 搜索框 -->
  10. <div class="search">
  11. <div class="inner">
  12. <input v-model="keywordInput" type="text" placeholder="请输入搜索内容">
  13. <button @click="goSearch">搜索</button>
  14. </div>
  15. </div>
  16. <div class="breadcrumb">
  17. <div class="inner">
  18. <span class="location">当前位置:</span>
  19. <el-breadcrumb :separator-icon="ArrowRight">
  20. <el-breadcrumb-item>
  21. <NuxtLink to="/">首页</NuxtLink>
  22. </el-breadcrumb-item>
  23. <el-breadcrumb-item>搜索</el-breadcrumb-item>
  24. </el-breadcrumb>
  25. </div>
  26. </div>
  27. <div class="newsList">
  28. <div class="inner">
  29. <div class="innerLeft">
  30. <ul class="list" v-if="newsList.length >= 0">
  31. <li v-for="(item, index) in newsList" :key="index">
  32. <NuxtLink :href="getLinkPathDetail(item)" :title="item.title" :target="item.islink == 1 ? '_blank' : '_self'">
  33. {{ item.title }}
  34. </NuxtLink>
  35. </li>
  36. </ul>
  37. <div v-if="newsList.length == 0" class="empty">
  38. <div>
  39. <img src="../../public/search/empty.png" alt="暂无内容">
  40. <p>暂无搜索数据</p>
  41. </div>
  42. </div>
  43. <!-- 分页器 -->
  44. <div class="pagination pagination_phone_none" v-if="total > 0">
  45. <el-pagination
  46. class="mt-4"
  47. size="small"
  48. background
  49. layout="prev, pager, next"
  50. :total="total"
  51. :page-size="pageSize"
  52. prev-text="上一页"
  53. next-text="下一页"
  54. @change="changePage"
  55. />
  56. </div>
  57. <div class="pagination pagination_pc_none" v-if="total > 0">
  58. <el-pagination
  59. pager-count="5"
  60. class="mt-4"
  61. size="small"
  62. background
  63. layout=" pager "
  64. :total="total"
  65. page-size="pageSize"
  66. @change="changePage"
  67. />
  68. </div>
  69. </div>
  70. </div>
  71. </div>
  72. <div class="advert_box clearfix">
  73. <!-- 列表页广告二 -->
  74. <HomeTopTen :imgurl="adImg2" v-if="adImg2"></HomeTopTen>
  75. </div>
  76. <!-- 页面底部 -->
  77. <HomeFoot1></HomeFoot1>
  78. </div>
  79. </template>
  80. <script setup>
  81. //1.页面依赖 start ---------------------------------------->
  82. import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus'
  83. import { ArrowRight } from '@element-plus/icons-vue'
  84. import { ref, onMounted } from 'vue';
  85. const route = useRoute();
  86. //const pageCatids = route.query.catids;
  87. const pageCatids = ""
  88. if(route.params.id=='search'){
  89. }else{
  90. const pageCatids = route.params.id
  91. }
  92. const pageDepartment_id = route.query.department_id;
  93. //const category_id = route.query.category_id; //获得该页面的id
  94. // const searchKey = route.query.keyword
  95. // const catids = ref([]);
  96. //关键词
  97. let total = useState("total", () => 0)
  98. let page = useState("page", () => 1)
  99. let pageSize = useState("pageSize", () => 20)
  100. //格式化跳转链接
  101. const getLinkPathDetail = (item) => {
  102. if (item.islink == 1) {
  103. return `${item.linkurl}`;
  104. } else {
  105. return `/${item.pinyin}/${item.id}.html`;
  106. }
  107. }
  108. //1.页面依赖 end ---------------------------------------->
  109. //2.页面数据 start ---------------------------------------->
  110. //2.1 广告
  111. let adImg1 = ref([]);
  112. let adImg2 = ref([]);
  113. // async function getAdData(){
  114. // const mkdata = await requestDataPromise('/web/getWebsiteAdvertisement',{
  115. // method:'GET',
  116. // query:{
  117. // 'ad_tag':'SEARCH'
  118. // }
  119. // });
  120. // if(adData.code==200){
  121. // for(let item of adData.data){
  122. // if(item.ad_tag == 'SEARCH_0001'){
  123. // adImg1.value = item;
  124. // }
  125. // if(item.ad_tag == 'SEARCH_0002'){
  126. // adImg2.value = item;
  127. // }
  128. // }
  129. // }else{
  130. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  131. // console.log("错误位置:获取搜索页广告列表")
  132. // console.log("后端错误反馈:",adData.message)
  133. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  134. // }
  135. // }
  136. // getAdData();
  137. onMounted(async () => {
  138. //从客户端获取行政职能部门 加快打开速度
  139. const { $webUrl, $CwebUrl } = useNuxtApp();
  140. //广告1
  141. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_search_0001`
  142. const responseAd1 = await fetch(url, {
  143. headers: {
  144. 'Content-Type': 'application/json',
  145. 'Userurl': $CwebUrl,
  146. 'Origin': $CwebUrl
  147. }
  148. });
  149. const resultAd1 = await responseAd1.json();
  150. adImg1.value = resultAd1.data[0];
  151. //广告2
  152. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_search_0002`
  153. const responseAd2 = await fetch(url2, {
  154. headers: {
  155. 'Content-Type': 'application/json',
  156. 'Userurl': $CwebUrl,
  157. 'Origin': $CwebUrl
  158. }
  159. });
  160. const resultAd2 = await responseAd2.json();
  161. adImg2.value = resultAd2.data[0];
  162. })
  163. // 新闻列表
  164. const newsList = ref([]);
  165. let keywordInput = ref("");
  166. //搜索
  167. let goSearch = async () => {
  168. console.log(page.value)
  169. console.log(pageSize.value)
  170. console.log(keywordInput.value)
  171. console.log(pageCatids)
  172. console.log(pageDepartment_id)
  173. const listData = await requestDataPromise('/web/selectWebsiteCategory', {
  174. method: 'GET',
  175. query: {
  176. 'page': page.value,
  177. 'pageSize': pageSize.value,
  178. 'keyword':keywordInput.value,
  179. 'cityid':pageCatids,
  180. 'department_id':pageDepartment_id
  181. },
  182. });
  183. if(listData.data.rows){
  184. console.log(listData)
  185. newsList.value = listData.data.rows;
  186. total.value = listData.data.count;
  187. }else{
  188. newsList.value = [];
  189. total.value = 0;
  190. }
  191. }
  192. goSearch();
  193. //基于导航池搜索
  194. // let goSearchFont = async (font) => {
  195. // const listData = await requestDataPromise('/web/getWebsiteArticleList', {
  196. // method: 'GET',
  197. // query: {
  198. // 'page': page.value,
  199. // 'pageSize': pageSize.value,
  200. // 'catid': font
  201. // },
  202. // });
  203. // newsList.value = listData.data.rows;
  204. // total.value = listData.data.count;
  205. // }
  206. // //基于导航池与关键词搜索
  207. // let goSearchFontandCid = async (font) => {
  208. // const listData = await requestDataPromise('/web/getWebsiteArticleList', {
  209. // method: 'GET',
  210. // query: {
  211. // 'page': page.value,
  212. // 'pageSize': pageSize.value,
  213. // 'catid': category_id,
  214. // 'keyword':searchKey
  215. // },
  216. // });
  217. // newsList.value = listData.data.rows;
  218. // total.value = listData.data.count;
  219. // }
  220. //直接查新闻
  221. // const newslists = async () => {
  222. // try {
  223. // // 从地区跳转
  224. // if (route.query.catids && route.query.catids.length > 0) {
  225. // // 将字符串转换回数组,并过滤掉可能的空值
  226. // catids.value = route.query.catids.split(',').filter(id => id);
  227. // if (catids.value.length > 0) {
  228. // // 有效的 catids 数组,可以进行后续操作
  229. // console.log('接收到的分类ID数组:', catids.value);
  230. // let font = catids.value.join(",")
  231. // font = "[" + font + "]"
  232. // goSearchFont(font);
  233. // } else {
  234. // // 处理空数组情况
  235. // console.log('未接收到有效的分类ID');
  236. // }
  237. // } else {
  238. // if (category_id == undefined) {
  239. // //直接搜索 默认进来没有导航池的话 不执行搜索
  240. // goSearch();
  241. // } else {
  242. // goSearchFontandCid();
  243. // }
  244. // }
  245. // } catch (error) {
  246. // console.error(error);
  247. // }
  248. // }
  249. // newslists();
  250. // 查询导航池的方法
  251. // const newslists = async () => {
  252. // try {
  253. // // 从地区跳转
  254. // if (route.query.catids && route.query.catids.length > 0) {
  255. // // 将字符串转换回数组,并过滤掉可能的空值
  256. // catids.value = route.query.catids.split(',').filter(id => id);
  257. // if (catids.value.length > 0) {
  258. // // 有效的 catids 数组,可以进行后续操作
  259. // console.log('接收到的分类ID数组:', catids.value);
  260. // let font = catids.value.join(",")
  261. // font = "[" + font + "]"
  262. // goSearchFont(font);
  263. // } else {
  264. // // 处理空数组情况
  265. // console.log('未接收到有效的分类ID');
  266. // }
  267. // } else {
  268. // if (category_id == undefined) {
  269. // //直接搜索 默认进来没有导航池的话 不执行搜索
  270. // goSearch();
  271. // } else {
  272. // goSearchFontandCid();
  273. // }
  274. // }
  275. // } catch (error) {
  276. // console.error(error);
  277. // }
  278. // }
  279. // newslists();
  280. //分页事件
  281. let changePage = (value) => {
  282. console.log("当前页码", value);
  283. page.value = value
  284. console.log(page.value);
  285. goSearch()
  286. }
  287. //2.页面数据 end ---------------------------------------->
  288. //4.设置seo信息 start---------------------------------------->
  289. //4.1 设置seo信息
  290. const setData = await requestDataPromise('/web/getWebsiteFootInfo', {
  291. method: 'GET',
  292. query: {},
  293. });
  294. let seoTitle = setData.data.website_head.title;
  295. let seoDescription = setData.data.website_head.description;
  296. let seoKeywords = setData.data.website_head.keywords;
  297. let seoSuffix = setData.data.website_head.suffix;
  298. let seoName = setData.data.website_head.website_name;
  299. useSeoMeta({
  300. title: seoTitle + "_" + seoSuffix,
  301. meta: [
  302. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix , tagPriority: 10 },
  303. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix , tagPriority: 10 },
  304. { name: 'viewport', content:"width=device-width,initial-scale=1,user-scalable=no"}
  305. ]
  306. });
  307. //4.设置seo信息 end---------------------------------------->
  308. </script>
  309. <style lang="less" scoped>
  310. @import url('@/assets/css/search.less');
  311. </style>
  312. <style lang="less" scoped>
  313. @media screen and (min-width:801px){/*pc*/
  314. .pagination_pc_none{display:none!important;}
  315. .pc_none{display:none;}
  316. }
  317. @media screen and (max-width:800px){/*ipad_phone*/
  318. .breadcrumb{margin-bottom:10px; }
  319. .breadcrumb .location{ font-size: 14px; margin-right:5px;}
  320. .breadcrumb span { font-size: 14px; }
  321. .newsList{width:100%;margin-bottom:22px;}
  322. .newsList .inner{width:92%!important;}
  323. .newsList .inner .innerLeft > .list > li{width:96%;margin:0px auto;}
  324. .newsList .inner .innerLeft{width:100%;}
  325. .newsList .inner .innerLeft > .list > li{line-height:50px;}
  326. .newsList .inner .innerLeft > .list > li > a{
  327. width:100%;display:block; height:50px;line-height:50px;font-size:16px;
  328. word-break: keep-all; white-space: nowrap;overflow:hidden;text-overflow:ellipsis;
  329. }
  330. .newsList .inner .innerLeft > .list > li a{float:left;width:92%; }
  331. .newsList .inner .innerLeft > .list > li:nth-of-type(-n+2)::after{display: block;height:18px;margin:10px 0px 0px 0px;
  332. font-size:12px;line-height:18px;float:right;}
  333. .newsList .inner .innerLeft > .pagination{width:100%;}
  334. .newsList .inner .innerLeft > .list{margin:10px auto 10px;}
  335. .newsList .inner .innerLeft > .pagination{margin-bottom:11px;}
  336. .newsList .inner .innerRight {width:100%;display:none;}
  337. .index_foot{margin-top:11px;}
  338. .search{ overflow:hidden;height:auto;
  339. width:92%;margin:10px auto;
  340. .inner{width:100%;display:flex;height:auto;padding:0;}
  341. .inner > input{ flex:1;width:auto;line-height:33px;height:33px;box-sizing:border-box;font-size:14px;}
  342. .inner > button{width:auto;padding:0px 8px;line-height:33px;height:33px;font-size:14px;}
  343. }
  344. ::v-deep .el-pager li{
  345. margin:0px 4px!important;
  346. }
  347. .advert_box{width:92%;margin:0px auto;}
  348. .pagination_phone_none{display:none!important;}
  349. .newsList .inner .innerLeft > .list > li{line-height:40px;height:40px;}
  350. .newsList .inner .innerLeft > .list > li a{line-height:40px;height:40px;}
  351. .newsList .inner .innerLeft > .list > li:nth-child(5n){
  352. height:auto;
  353. padding-bottom:11px;
  354. margin-bottom:11px;
  355. }
  356. .phone_none{display:none;}
  357. }
  358. </style>